package com.ztq.test.userinfo.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.ztq.test.login.entity.T_userInfo;

/**
 * @author: ztq
 * @date: 2016-2-1 下午05:03:41
 * @description: 
 * @version:1.0
 */
public class UserHandlerUtil {
	//将获取到的用户好友信息转化为json字符串
	public static String getUserFriendshipInfoJson(List<T_userInfo> list){
		JSONArray jarray = new JSONArray();
		JSONObject obj = null;
		T_userInfo userInfo;
		
		for(Iterator<T_userInfo> iterator = list.iterator();iterator.hasNext();){
			userInfo = iterator.next();
			obj = new JSONObject();
			obj.put("user_id", userInfo.getUser_id());
			obj.put("username", userInfo.getUsername());
			obj.put("nickname", userInfo.getNickname());
			obj.put("sex", userInfo.getSex());
			obj.put("phone", userInfo.getPhone());
			obj.put("province", userInfo.getProvince());
			obj.put("city", userInfo.getCity());
			obj.put("signature", userInfo.getSignature());
			obj.put("user_remark", userInfo.getUser_remark());
			jarray.add(obj);
		}
		String result = null;
		try {
			result = URLEncoder.encode(jarray.toString(), "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return result;
	}
}